package com.fr.report.script.function;

import com.fr.base.BaseUtils;
import com.fr.base.FRContext;
import com.fr.base.StringUtils;
import com.fr.base.dav.Env;
import com.fr.report.script.Function;
import com.fr.report.script.Function.Type;
import com.fr.report.script.NormalFunction;
import com.fr.report.script.Primitive;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;

public class TOIMAGE extends NormalFunction
{
  public Object run(Object[] paramArrayOfObject)
  {
    if (paramArrayOfObject.length < 1)
      return Primitive.ERROR_NAME;
    Object localObject = paramArrayOfObject[0];
    if (localObject instanceof String)
      try
      {
        String str1 = (String)localObject;
        if ((str1.endsWith("/")) || (str1.endsWith("\\")))
          localObject = str1.substring(0, ((String)localObject).length() - 1);
        BufferedImage localBufferedImage = BaseUtils.readImage(((String)localObject).trim());
        if ((localBufferedImage == null) && (FRContext.getCurrentEnv() != null) && (StringUtils.isNotBlank((String)localObject)))
        {
          String str2 = new File(FRContext.getCurrentEnv().getPath()).getParent() + File.separator + localObject;
          localBufferedImage = BaseUtils.readImage(str2);
        }
        return localBufferedImage;
      }
      catch (Exception localException)
      {
        FRContext.getLogger().log(Level.WARNING, localException.getMessage(), localException);
      }
    return Primitive.ERROR_NAME;
  }

  public Function.Type getType()
  {
    return Function.OTHER;
  }

  public String getCN()
  {
    return "TOIMAGE(path):返回path路径下的image。";
  }

  public String getEN()
  {
    return "";
  }
}